# -*- coding: UTF-8 -*-
"""
@Project ：Webpage 
@File    ：1.py
@IDE     ：PyCharm 
@Author  ：于金龙@阿龙的代码在报错
@Date    ：2025/2/19 下午4:15 
"""
import pymysql
from flask import Flask, render_template

app = Flask(__name__)

# 数据库连接配置
db_config = {
    'host': 'localhost',
    'user': 'root',
    'password': '20020115',
    'db': 'resume'
}


@app.route('/')
def index():
    # 连接到数据库
    connection = pymysql.connect(**db_config)
    try:
        with connection.cursor() as cursor:
            # 执行SQL查询
            sql = "SELECT resume.resume.download FROM resume WHERE resume.r_id=130840"
            cursor.execute(sql)
            result = cursor.fetchone()  # 假设我们只想要一个结果
            print(result)

            # 检查是否有结果
            if result:
                url = result[0]
            else:
                url = None  # 或者你可以设置一个默认值

    finally:
        connection.close()

    # 渲染模板并传递URL
    return render_template('index.html', url=url)


if __name__ == '__main__':
    app.run(debug=True)
